#include "src/core/logger/loggerrecord.h"
#include "src/core/generic/translator.h"
#include <boost/algorithm/string.hpp>

LoggerRecord::string_type LoggerRecord::text() const
{
  extern Translator translator;
  std::string tmp;
  std::vector<std::string> lines;
  switch (_record)
  {
  case NewDocument:
    return translator.stdString("New document created.");
   case DocumentSaved:
    tmp = translator.stdString("Document \"%1\" saved.");
    boost::algorithm::replace_first(tmp, "%1", _params);
    return tmp;
  case DocumentClosed:
    tmp = translator.stdString("Document \"%1\" closed.");
    boost::algorithm::replace_first(tmp, "%1", _params);
    return tmp;
  case FileOpened:
    tmp = translator.stdString("File \"%1\" loaded.");
    boost::algorithm::replace_first(tmp, "%1", _params);
    return tmp;
  case FileOpenError:
    tmp = translator.stdString("Error opening file \"%1\".");
    boost::algorithm::replace_first(tmp, "%1", _params);
    return tmp;
  case FileParsingErrorFiletype:
    tmp = translator.stdString("Cannot detect filetype of \"%1\".");
    boost::algorithm::replace_first(tmp, "%1", _params);
    return tmp;
  case FileParsingUnknownFiletype:
    tmp = translator.stdString("Unknown filetype of \"%1\". Trying to guess...");
    boost::algorithm::replace_first(tmp, "%1", _params);
    return tmp;
  case ParsingBadAtomIndex:
    boost::algorithm::split(lines, _params, boost::algorithm::is_any_of("\t"));
    tmp = translator.stdString("Parsing file \"%1\" line %2: negative or zero atom index.");
    boost::algorithm::replace_first(tmp, "%1", lines[0]);
    boost::algorithm::replace_first(tmp, "%2", lines[1]);
    return tmp;
  case ParsingBadAtomEntry:
    boost::algorithm::split(lines, _params, boost::algorithm::is_any_of("\t"));
    tmp = translator.stdString("Parsing file \"%1\" line %2: unexpected syntax. Expected : <code>\"{int} {string} {real} {real} {real} {string} [ {int} [ {string} [ {real} [ {string} ]]]]\"</code>.");
    boost::algorithm::replace_first(tmp, "%1", lines[0]);
    boost::algorithm::replace_first(tmp, "%2", lines[1]);
    return tmp;
  case ParsingBadBondIndex:
    boost::algorithm::split(lines, _params, boost::algorithm::is_any_of("\t"));
    tmp = translator.stdString("Parsing file \"%1\" line %2: negative or zero bond index.");
    boost::algorithm::replace_first(tmp, "%1", lines[0]);
    boost::algorithm::replace_first(tmp, "%2", lines[1]);
    return tmp;
  case NoCorrespondingAtom:
    boost::algorithm::split(lines, _params, boost::algorithm::is_any_of("\t"));
    tmp = translator.stdString("Parsing file \"%1\". No corresponding atom for bond %2 : %3 - %4.");
    boost::algorithm::replace_first(tmp, "%1", lines[0]);
    boost::algorithm::replace_first(tmp, "%2", lines[1]);
    boost::algorithm::replace_first(tmp, "%3", lines[2]);
    boost::algorithm::replace_first(tmp, "%4", lines[3]);
    return tmp;
  case ParsingAtomPropertiesError:
    boost::algorithm::split(lines, _params, boost::algorithm::is_any_of("\t"));
    tmp = translator.stdString("Parsing file \"%1\". %2 - Col: %3 Row: %4");
    boost::algorithm::replace_first(tmp, "%1", lines[0]);
    boost::algorithm::replace_first(tmp, "%2", lines[1]);
    boost::algorithm::replace_first(tmp, "%3", lines[2]);
    boost::algorithm::replace_first(tmp, "%4", lines[3]);
    return tmp;
  case ParsingAtomPropertiesUnknownTagError:
    boost::algorithm::split(lines, _params, boost::algorithm::is_any_of("\t"));
    tmp = translator.stdString("Parsing file \"%1\". Unknown Tag \"%2\" - Col: %3 Row: %4");
    boost::algorithm::replace_first(tmp, "%1", lines[0]);
    boost::algorithm::replace_first(tmp, "%2", lines[1]);
    boost::algorithm::replace_first(tmp, "%3", lines[2]);
    boost::algorithm::replace_first(tmp, "%4", lines[3]);
    return tmp;
  case ParsingAtomPropertiesNoStyleNameError:
    boost::algorithm::split(lines, _params, boost::algorithm::is_any_of("\t"));
    tmp = translator.stdString("Parsing file \"%1\". Style has no name - Col: %2 Row: %3");
    boost::algorithm::replace_first(tmp, "%1", lines[0]);
    boost::algorithm::replace_first(tmp, "%2", lines[1]);
    boost::algorithm::replace_first(tmp, "%3", lines[2]);
    return tmp;
  case ParsingAtomPropertiesUnknownPrimitiveError:
    boost::algorithm::split(lines, _params, boost::algorithm::is_any_of("\t"));
    tmp = translator.stdString("Parsing file \"%1\". Unknown primitive \"%2\" - Col: %3 Row: %4");
    boost::algorithm::replace_first(tmp, "%1", lines[0]);
    boost::algorithm::replace_first(tmp, "%2", lines[1]);
    boost::algorithm::replace_first(tmp, "%3", lines[2]);
    boost::algorithm::replace_first(tmp, "%4", lines[3]);
    return tmp;
  case ParsingAtomPropertiesBadAtomZ:
    boost::algorithm::split(lines, _params, boost::algorithm::is_any_of("\t"));
    tmp = translator.stdString("Parsing file \"%1\". Too big atomic number \"%2\" - Col: %3 Row: %4");
    boost::algorithm::replace_first(tmp, "%1", lines[0]);
    boost::algorithm::replace_first(tmp, "%2", lines[1]);
    boost::algorithm::replace_first(tmp, "%3", lines[2]);
    boost::algorithm::replace_first(tmp, "%4", lines[3]);
    return tmp;
  case ParsingAtomPropertiesBadParameterQuantity:
    boost::algorithm::split(lines, _params, boost::algorithm::is_any_of("\t"));
    tmp = translator.stdString("Parsing file \"%1\". Incorrect color attribute \"%2\" quantity - Col: %3 Row: %4");
    boost::algorithm::replace_first(tmp, "%1", lines[0]);
    boost::algorithm::replace_first(tmp, "%2", lines[1]);
    boost::algorithm::replace_first(tmp, "%3", lines[2]);
    boost::algorithm::replace_first(tmp, "%4", lines[3]);
    return tmp;
  case ParsingAtomPropertiesBadColorValue:
    boost::algorithm::split(lines, _params, boost::algorithm::is_any_of("\t"));
    tmp = translator.stdString("Parsing file \"%1\". Bad color value \"%2\" quantity - Col: %3 Row: %4");
    boost::algorithm::replace_first(tmp, "%1", lines[0]);
    boost::algorithm::replace_first(tmp, "%2", lines[1]);
    boost::algorithm::replace_first(tmp, "%3", lines[2]);
    boost::algorithm::replace_first(tmp, "%4", lines[3]);
    return tmp;
  default:
    return string_type();
  }
}
